package com.bw.lib_log

import com.bw.lib_log.logger.*

/**
 * @Author : ZhouZiYao
 * @Time : On 2023/11/13 13:43
 * @Description : Logger
 */
class Logger private constructor(private val tag:String,private val isDebug:Boolean,private val level: LoggerLevel,private val url: String,private val loggerStrategy:LoggerStrategy) {
    private var logger: ILogger
    init {
        logger = when(loggerStrategy){
            LoggerStrategy.LOGCAT -> LogCatLogger()
            LoggerStrategy.FILE -> FileLogCat()
            LoggerStrategy.EMAIL -> EmailLogger()
            LoggerStrategy.NET -> NetLogger()
        }
        logger.setLoggerLever(level)
        logger.setLogTag(tag)
        logger.setDebug(isDebug)
        logger.setSaveUrl(url)
    }

    fun d(tag: String, log: String){
        logger.d(tag, log)
    }

    fun v(tag: String, log: String){
        logger.v(tag, log)
    }

    fun i(tag: String, log: String){
        logger.i(tag, log)
    }

    fun w(tag: String, log: String){
        logger.w(tag, log)
    }

    fun e(tag: String, log: String){
        logger.e(tag, log)
    }

    //构建者
    constructor(builder: Logger.Builder):this(
        builder.tag,
        builder.isDebug,
        builder.level,
        builder.url,
        builder.loggerStrategy
    )

    class Builder{
        var isDebug: Boolean = true
        var tag: String = ""
        var level: LoggerLevel = LoggerLevel.Debug
        var url: String = ""
        var loggerStrategy: LoggerStrategy = LoggerStrategy.LOGCAT

        fun setDebug(isDebug: Boolean): Builder {
            this.isDebug = isDebug
            return this
        }

        fun setTag(tag: String): Builder {
            this.tag = tag
            return this
        }

        fun setLevel(level: LoggerLevel): Builder {
            this.level = level
            return this
        }

        fun setSaveUrl(url: String): Builder {
            this.url = url
            return this
        }

        fun setStrategy(loggerStrategy: LoggerStrategy): Builder {
            this.loggerStrategy = loggerStrategy
            return this
        }

        fun build(): Logger {
            return Logger(this)
        }
    }

}